<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
</head>
<body>
	<form id="form" class="layui-form layui-form-pane" >
	  <div class="layui-form-item">
	    <label class="layui-form-label">名字</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">年龄</label>
	    <div class="layui-input-block">
	      <input type="text" name="age" lay-verify="required" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item" pane="">
	    <label class="layui-form-label">性别</label>
	    <div class="layui-input-inline">
	      <input type="radio" name="gender" value="男" title="男" checked="">
	      <input type="radio" name="gender" value="女" title="女">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">日期</label>
	    <div class="layui-input-inline">
	      <input type="text" id="birthday" name="birthday" class="layui-input" autocomplete="off" placeholder="yyyy-MM-dd">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">班级</label>
	    <div class="layui-input-inline">
	      <select name="banji.id">
				<c:forEach items="${list}" var="banji">
					<option value="${banji.id}">${banji.name}</option>
				</c:forEach>
			</select>
	    </div>
	  </div>
	</form>
	<button class="layui-btn" onclick="submitForm()">添加</button>
	
	<script src="${pageContext.request.contextPath}/js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/js/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		layui.use(['form', 'table', 'laydate'], function() {
			var table = layui.table;
			var form = layui.form;
			var laydate = layui.laydate;
			  
			laydate.render({
			   elem: '#birthday',
			   trigger: 'click'
			});
			
		});
		
		function submitForm() {
			$.post(
				"${pageContext.request.contextPath}/student/insert.action",
				$("#form").serialize(),
				function(result) {
					console.log(result);
					if(result.success) {
						// mylayer.successUrl(result.msg, "${pageContext.request.contextPath}/student/getStudentListPage.action");
						
						mylayer.successMsg(result.msg);
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
						var index = parent.layer.getFrameIndex(window.name);
						// js一个方法，定时器，1000毫秒之后自动执行function里面的代码
						setTimeout(function() {
							 // 关闭弹出层
							 parent.layer.close(index); 
							 // 刷新父页面
							 window.parent.location.reload();
						}, 1000);
					} else {
						mylayer.errorMsg(result.msg);
					}
				},
				"json"
			);
			
		}
	</script>
	
</body>
</html>